<template>
	<view class="wrap">
		<!-- <view style="background-color: #fff;border-radius: 16rpx;">
			<u-cell-item title="车牌号" :value="bindCarPlate" :arrow="false" hover-class="none"></u-cell-item>
		</view> -->
		<view style="display: flex;align-items: center;justify-content: flex-end;margin: 10rpx 0;">
			<u-button @click="getLocal()" type="primary" size="mini">重新获取</u-button>
		</view>
		<view style="background-color: #fff;border-radius: 16rpx;margin-top: 20rpx;">
			<u-cell-item title="工地纬度" :value="model.offCarLat" :arrow="false" hover-class="none"></u-cell-item>
			<u-cell-item title="工地经度" :value="model.offCatLon" :arrow="false" hover-class="none"></u-cell-item>
		</view>
		<view style="padding: 0 30rpx;background-color: #fff;margin-top: 20rpx;">
			<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
				<u-form-item :label-position="labelPosition" label="处置场所名称" prop="soilName">
					<u-input :border="border" placeholder="请输入处置场所名称" v-model="model.soilName" type="text"></u-input>
				</u-form-item>
				<!-- <u-form-item :label-position="labelPosition" label="处置场所地址" prop="name">
					<u-input :border="border" placeholder="请输入处置场所地址" v-model="model.name" type="text"></u-input>
				</u-form-item> -->
				<!-- <u-form-item :label-position="labelPosition" label="接收垃圾类型" prop="goodsType">
					<u-input :border="border" type="select" :select-open="selectShow" v-model="model.goodsType"
						placeholder="请选择接收垃圾类型" @click="selectShow = true"></u-input>
				</u-form-item> -->
				<!-- <u-form-item :label-position="labelPosition" label="负责人姓名" prop="name">
					<u-input :border="border" placeholder="请输入负责人姓名" v-model="model.name" type="text"></u-input>
				</u-form-item> -->
				<u-form-item :label-position="labelPosition" label="接收量" prop="receivingQuantity">
					<u-input :border="border" placeholder="请输入接收量" v-model="model.receivingQuantity"
						type="text"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label="备注信息" prop="remark">
					<u-input :border="border" placeholder="请输入备注信息" v-model="model.remark" type="textarea"></u-input>
				</u-form-item>
			</u-form>
		</view>
		<view style="margin-top: 30rpx;">
			<u-button @click="submit" type="primary">提交</u-button>
		</view>
		<u-select mode="single-column" :list="selectList" v-model="selectShow" @confirm="selectConfirm"></u-select>
	</view>
</template>

<script>
	export default {
		data() {
			let that = this;
			return {
				model: {
					"offCarLat": '',
					"offCatLon": '',
					"jointOrderStatus": 2,
					"soilSiteCompanyId": '', //处置场所企业ID
					"soilName": "", //处置场所名称
					"receivingQuantity": "", //接收量（吨）
					id: '',
					remark: ''
				},
				rules: {
					name: [{
						required: true,
						message: '请输入姓名',
						trigger: 'blur',
					}, ],
				},
				border: false,
				labelPosition: 'top',
				errorType: ['toast'],
			};
		},
		onLoad(opt) {
			this.model.id = opt.orderId
			this.model.soilSiteCompanyId = opt.soilSiteCompanyId
			this.model.receivingQuantity = opt.receivingQuantity
			this.getLocal()
			this.getData()
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过');
						this.endOrder()
					} else {
						console.log('验证失败');
					}
				});
			},
			getData() {
				this.$u.get("/driver/soilSiteInfoPage", {
					'id': this.model.soilSiteCompanyId
				}).then(res => {
					if (res.code) {
						let data = res.rows[0]
						this.model.soilName = data.soilName //处置场所名称

					}
				})
			},
			//获取车辆经纬度
			getLocal() {
				console.log("ss")
				let that = this
				uni.getLocation({
					type: 'gcj02',
					success: function(res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						that.model.offCarLat = res.latitude
						that.model.offCatLon = res.longitude
					}
				});
			},
			endOrder() {
				this.$u.post("/driver/changeOrder", this.model).then(res => {
					if (res.code == 200) {
						uni.redirectTo({
							url:"/pages/order/detail/detail?id="+this.model.id
						})
						// uni.switchTab({
						// 	url: "/pages/order/order?index=2"
						// })
					}
				})
			},
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}
</style>